add_definitions(-D_POSIX_C_SOURCE=20190115 -DBUILD_REWINE)

#set(CMAKE_C_VISIBILITY_PRESET hidden)
#set(CMAKE_CXX_VISIBILITY_PRESET hidden)

add_library(rewine SHARED)
target_sources(rewine
        PRIVATE dllso/DllsoInit.cpp
        PRIVATE dso/DsoLoader.cpp
        PRIVATE interop/ElfInterop.cpp
        PRIVATE interop/ImageHandler.cpp
        PRIVATE interop/PathResolver.cpp
        PRIVATE interop/SymbolGetter.cpp
        PRIVATE interop/SymbolSetter.cpp
        PRIVATE misc/arch.cpp
        PRIVATE misc/fs_ext.cpp
        PRIVATE misc/helper.cpp
        PRIVATE misc/pvdtors.cpp
        PRIVATE misc/string_ext.cpp
        PRIVATE misc/version.cpp
        PRIVATE rewine/LibManager.cpp
        PRIVATE rewine/Loader.cpp
        PRIVATE rewine/LoaderSingleton.cpp
        PRIVATE rewine/Logger.cpp
        PRIVATE rewine/LoggerSingleton.cpp
        PRIVATE rewine/MapIndicator.cpp
        PRIVATE rewine/PathResolver.cpp
        PRIVATE rewine/SymbolResolver.cpp
        PRIVATE rewine/impl/CImage.cpp
        PRIVATE rewine/impl/CCustomImage.cpp
        PRIVATE rewine/impl/CDllsoImage.cpp
        PRIVATE rewine/impl/CDsoImage.cpp
        PRIVATE rewine/impl/CPeImage.cpp
        )
target_include_directories(rewine
        PUBLIC "${PROJECT_SOURCE_DIR}/include-public"
        PRIVATE "${PROJECT_SOURCE_DIR}/include"
        )
set_target_properties(rewine PROPERTIES
        #NO_SONAME 1
        PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include-public/rewine.h
        )
target_compile_options(rewine
        PRIVATE -fPIC -O0 -g -ggdb3
        )
add_dependencies(rewine
        # wine
        spdlog::spdlog
        )
target_link_libraries(rewine
        #PRIVATE -static-libgcc
        #PRIVATE -static-libstdc++
        PRIVATE dl
        PRIVATE spdlog::spdlog_header_only
        )
target_link_options(rewine
        PRIVATE LINKER:-soname,librewine.so.1
        #PRIVATE LINKER:--version-script,${CMAKE_CURRENT_SOURCE_DIR}/librewine.map
        )

# includes

#configure_file(
#        "${PROJECT_SOURCE_DIR}/include/rewine.h"
#        "${PROJECT_BINARY_DIR}/include/rewine.h"
#        COPYONLY
#)

# Create logs directory
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")

install(TARGETS rewine
        PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
